<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>

    <meta charset="UTF-8">  
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link href="${ctx}/resources/semanticui/semantic.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
    <title>面试状态</title>  
    
</head>
<body>
<div class="ui segment" id="n-page">
&nbsp;<br>
<!-- 所在城市  现任职位   工作状态+电话（电话一栏用***表示，包括自荐，猎头推荐及系统匹配）+推荐人&nbsp;<br/> -->
候选人：${person.name}&nbsp;<br>&nbsp;<br>
 年龄：<b>${person.age}</b>&nbsp;<br>&nbsp;<br>
所在城市：
	<c:choose>
        <c:when test="${person.cityId == 0 }">
            ${person.cityName}
        </c:when>
        <c:otherwise>
            ${city.name}
        </c:otherwise>
    </c:choose>
    &nbsp;<br>&nbsp;<br>
 现任公司：
	<c:choose>
        <c:when test="${person.companyId == 0 }">
            ${person.companyName}
        </c:when>
        <c:otherwise>
            ${company.name}
        </c:otherwise>
    </c:choose>
    &nbsp;<br>&nbsp;<br>
        现任职位：<b>${person.roleName}</b>&nbsp;<br>&nbsp;<br>
        工作年限：<b>${person.workage}</b>&nbsp;<br>&nbsp;<br>
<c:choose>
    <c:when test="${recommend.status > 0 }">
    电话：<b>${person.phone}</b>&nbsp;<br>&nbsp;<br>
                 
        <c:if test="${recommend.resid != null}">
        候选人简历：
        <img class="ui fluid image" src="${ctx}/rs/${recommend.resid}.jpg">
        <br>
        </c:if>
	<c:if test="${recommend.audioid != null}">
        候选人自我介绍：
           <button class="icon-audio" id="playerBtn" style="margin:0 5px;cursor:pointer;" 
        playerurl="${ctx}/rs/audio/${recommend.audioid}.amr">播放</button>  
		<div style="width:1px;height:1px;" id="playerQT">  
		  
		 </div> 
   
        <br>
    </c:if>
        
        <br>&nbsp;<br>
    </c:when>
    <c:otherwise>
    	电话：<b>********</b>&nbsp;<br>&nbsp;<br>
    </c:otherwise>
</c:choose>

推荐人：<%-- ${createPerson} --%>
<c:choose>
<c:when test="${recommend.personId == recommend.createby}">
	自荐
</c:when>
<c:when test="${recommend.personId != recommend.createby}">
	他荐
</c:when>
<c:otherwise>
	系统推荐
</c:otherwise>
</c:choose>
&nbsp;<br>&nbsp;<br>
	<c:choose>
    <c:when test="${recommend.status > 0 }">
    <h3 class="ui attached header" id="list-title">
        面试状态
    </h3>
    &nbsp;<br>
    <div class="ui attached segment" id="list-items">

    <c:forEach items="${interviews}" var="iv">
        <div class="ui segment listitem">
            日期： ${iv.updateTime}<br>类型：
            <c:choose>
                <c:when test="${(iv.itype ==1)}">
                    电话面试
                </c:when> 
   <%--              <c:when test="${(iv.itype ==2)}">
                    公司面试
                </c:when> 
                <c:when test="${(iv.itype ==3)}">
                    笔试
                </c:when>  --%>
                <c:when test="${(iv.itype ==4)}">
                    业务面试
                </c:when> 
                <c:when test="${(iv.itype ==5)}">
                    人事面试
                </c:when>  
                <c:when test="${(iv.itype ==6)}">
                    公司终面
                </c:when>               
                <c:otherwise>
                   谈薪资
                </c:otherwise>
            </c:choose>    
            <br>结果：
            <c:choose>
                <c:when test="${(iv.status ==1)}">
                    已发面试邀请
                </c:when> 
                <c:when test="${(iv.status ==2)}">
                    建议继续面试
                </c:when> 
                <c:when test="${(iv.status ==3)}">
                    拒绝
                </c:when> 
                <c:when test="${(iv.status ==4)}">
                    录用
                </c:when> 
                <c:when test="${(iv.status ==6)}">
                   未录用
                </c:when> 
                <c:when test="${(iv.status ==7)}">
                    候选人拒绝
                </c:when> 
                 <c:when test="${(iv.status ==8)}">
                    候选人不合格
                </c:when> 
                <c:when test="${(iv.status ==9)}">
                    薪资没谈拢
                </c:when> 
                <c:when test="${(iv.status ==10)}">
                    入职
                </c:when> 
                <c:when test="${(iv.status ==11)}">
                    未入职
                </c:when> 
                <c:otherwise>
                    奖金已发放
                </c:otherwise>
            </c:choose>    
            <br> 
            	反馈：${iv.remark}
        </div>
    </c:forEach>
        
    </div>

    <h3 class="ui attached header" id="list-title2">
        面试反馈记录
    </h3>
    <div class="ui attached segment" id="list-items2">
        <form class="ui form" id="feedBackForm">
            <div class="field">
                <label>选择日期</label>
                <div class="ui input">
                    <input type="date" name="updatedate" id="updatedate" value="${todayStr}">
                </div>
            </div>
            <div class="field">
                <label>面试类型</label>
                <select class="ui selection dropdown" id="itype" name="itype">
                    <option value="1">电话面试</option>
                    <!-- <option value="2">公司面试</option>
                    <option value="3">笔试</option> -->
                    <option value="4">业务面试</option>
                    <option value="5">人事面试</option>
                    <option value="6">公司终面</option>
                    <option value="7">谈薪资</option>
                </select>
            </div>
            <div class="field">
                <label>面试结果</label>
                <select class="ui selection dropdown" id="status" name="status">
                    <!--<option value="1">已发面试邀请</option>-->
                    <option value="2">建议继续面试</option>
                    <option value="3">拒绝</option>
                    <option value="4">录用</option>
                    <option value="6">未录用</option>
                    <option value="7">候选人拒绝</option>
                    <option value="8">候选人不合格</option>
                    <option value="9">薪资没谈拢</option>
                    <option value="10">入职</option>
                    <option value="11">未入职</option>
                    <!--
                    <option value="5">奖金已发放</option>
                    -->
                </select>
            </div>
            <div class="field">
            	<label>面试反馈</label>
            	<div class="ui input">
                    <input type="text" name="remark" id="remark" placeholder="请输入反馈信息（必填项）" value="" >
                </div>
            </div>
        </form>
    </div>

    <div class="ui segment" id="btn-next2">
        <div class="fluid ui button submitBtn" id="next">提交结果</div>
    </div>
	</c:when>
	</c:choose>
    <div class="ui center aligned segment" id="choice-buttons"> 
        <div class="two ui buttons"> 
             <c:choose>
   			 	<c:when test="${recommend.status > 0 }">
     			<div class="ui button active dog" id="bonus">发放奖金</div> 
     			 <div class="ui button dog" id="ask">面试邀请</div>
     			</c:when>
     			 <c:otherwise>
     				 <div class="ui segment" id="btn-next2">
    					<div class="fluid ui button" style="align:center;" id="ask">面试邀请</div>
    				  </div>
    			</c:otherwise>
     			</c:choose>
            
        </div>
    </div>
    <input type="hidden" name="recommendstatus" id="recommendstatus" value="${recommend.status}" />

</div>
<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semanticui/semantic.js" type="text/javascript"></script>
<script type="text/javascript">

wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu']  
});

    var datasource = { 
        appenddata:function(data) {
            var divstring  = '';
            divstring += '<div class="ui segment listitem">';
            divstring += '日期： ';
            divstring += data.updateTime;
            divstring += '<br>';
            divstring += '类型：';
            if(data.itype == 1) {
                divstring += '电话面试';
            } 
           /*  else if(data.itype == 2) {
                divstring += '公司面试';
            }  */
          /*   else if(data.itype == 3) {
                divstring += '笔试';
            }  */
            else if(data.itype == 4) {
                divstring += '业务面试';
            } else if(data.itype == 5) {
                divstring += '人事面试';
            } else if(data.itype == 6) {
                divstring += '公司终面';
            } else{
                divstring += '谈薪资';
            } 
            divstring += '<br>';
            divstring += '结果：';
            if(data.status == 1) {
                divstring += '已发面试邀请';
            } else if(data.status == 2) {
                divstring += '建议继续面试';
            } else if(data.status == 3) {
                divstring += '拒绝';
            } else if(data.status == 4) {
                divstring += '录用';
            } else if(data.status == 6) {
                divstring += '未录用';
            } else if(data.status == 7) {
                divstring += '候选人拒绝';
            } else if(data.status == 8) {
                divstring += '候选人不合格';
            } else if(data.status == 9) {
                divstring += '薪资没谈拢';
            } else if(data.status == 10) {
                divstring += '入职';
            } else if(data.status == 11) {
                divstring += '未入职';
            }else {
                divstring += '奖金已发放';
            }
            divstring += '<br> 面试反馈：';
            divstring += data.remark;
            var newdata = $(divstring);
            $('#list-items').append(newdata);
        },

        postdata:function(postdata) {
            var postUrl = '${ctx}/wechat/hunter/creatInterview.do?recommendid=' + ${recommend.id};
            var that = this;

            $.ajax({
                url: postUrl,
                type: "POST",
                data: postdata,
                success:function(data, status) {
                    if(data.errorcode == 0 || data.errorcode == 2) {
                        that.appenddata(postdata);
                    } else if(data.errorcode == 1) {
                        alert(data.msg);
                    }else {
                        alert(data.msg);
                    }
                },
                error: function() {
                    alert("服务出错，请稍后尝试");
                }
            });
        },

        getdata:function(actiontype) {
            var getUrl = "";
            if(actiontype == "bonus") {
                getUrl = '${ctx}/wechat/hunter/updateInterviewStatus.do?action=bonus&recommendid=' + ${recommend.id};
            } else {
                getUrl = '${ctx}/wechat/hunter/updateInterviewStatus.do?action=ask&recommendid=' + ${recommend.id};
            }
            var that = this;

            $.ajax({
                url: getUrl,
                type: "GET", 
                success:function(data, status) {
                    if(data.errorcode == 0 || data.errorcode == 2) {
                        that.appenddata(data.data);
                    } else if(data.errorcode == 1) {
                        alert(data.msg);
                    } else {
                        alert(data.msg);
                    }
                },
                error: function() {
                    alert("服务出错，请稍后尝试");
                }
            });
        }
    };

    var handler = {      
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active');           
            if($(this).attr('id') == 'next') {
                var postData = {};

                var status = $("#status").val();
                var updatedate = $("#updatedate").val();
                var itype = $("#itype").val();
                var remark = $("#remark").val();

                postData['status'] = status;
                postData['updateTime'] = updatedate;
                postData['itype'] = itype;
                postData['remark'] = remark;
                datasource.postdata(postData);
            }
            if($(this).attr('id') == 'bonus') {
                datasource.getdata('bonus');
            }
            if($(this).attr('id') == 'ask') {
                datasource.getdata('ask');
            }
        } 
    };
    
    function submitFeedBack(postdata){    	 
	      var remark = $("#remark").val();
	      if(!remark || remark =="") {
	         alert("反馈是必填项");
	         return false;
	       }

         var postUrl = '${ctx}/wechat/hunter/creatInterview.do?recommendid=' + ${recommend.id};
         var that = this;

         $.ajax({
             url: postUrl,
             type: "POST",
             data: postdata,
             success:function(data, status) {
                 
            	 if(data.errorcode == 0 || data.errorcode == 2) {
            		 datasource.appenddata(postdata);                    
            		 $("#status").val();
                     $("#updatedate").val();
                     $("#itype").val();
                     $("#remark").val("");
                     
                 } else if(data.errorcode == 1) {
                     alert(data.msg);
                 }else {
                     alert(data.msg);
                 }
            	 
             },
             error: function() {
                 alert("服务出错，请稍后尝试");
             }
         });
    }
    
    $(document).ready(function() {     	 
           //$('.submitBtn').on('click', handler.activate);
           
           $(".submitBtn").click(function(){
        	   //提交表单
        	   var postData = {};

               var status = $("#status").val();
               var updatedate = $("#updatedate").val();
               var itype = $("#itype").val();
               var remark = $("#remark").val();

               postData['status'] = status;
               postData['updateTime'] = updatedate;
               postData['itype'] = itype;
               postData['remark'] = remark;
               
               submitFeedBack(postData);
           });
           
           $('.dropdown').dropdown({
               fullTextSearch:true,
           });

           var recommendstatus = $('#recommendstatus').val();
           if(recommendstatus == 0) {
               $('#next').addClass('disabled');
               $('#bonus').addClass('disabled');
           }else if(recommendstatus == 2){
                $('#bonus').addClass('disabled');
           }else if(recommendstatus == 3||recommendstatus == 6||
        		   recommendstatus == 7||recommendstatus == 8||
        		   recommendstatus == 9||recommendstatus == 11){
           	 $('#next').addClass('disabled');//提交结果
                $('#bonus').addClass('disabled');//发放奖金
                $('#ask').addClass('disabled');//面试邀请
           }else if(recommendstatus == 10){
           	 $('#next').addClass('disabled');
             $('#ask').addClass('disabled');
           }else if(recommendstatus == 1||recommendstatus == 4){
        	  $('#bonus').addClass('disabled');//发放奖金
              /* $('#ask').addClass('disabled');//面试邀请 */
           }
           
          var playerQT = document.getElementById("playerQT");  
           $("#playerBtn").bind("click",function(e){  
               var playerUrl = e.target.getAttribute("playerUrl");  
               playerAudio(playerUrl);  
           });  
           function playerAudio(url){  
               var html ="<audio class='icon-audio' id='player' style='margin:0 5px;cursor:pointer;' src='"+url+"' autoplay preload loop controls>播放</audio >";
               playerQT.innerHTML = html;  
           }
            
           wx.ready(function() {
        	    document.getElementById('player').play();
           		wx.hideOptionMenu();
           });
    });
    
    
</script>
</body>
</html>